package com.eerl.pdev;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

//@State 注解用于指定组件的状态名称和存储位置。
// @Storage 注解指定了存储的类型，这里使用 StoragePathMacros.WORKSPACE_FILE 表示将状态保存在工作区文件中。
@State(name = "com.eerl.pdev.MyPluginState", storages = {@Storage("MyPluginState.xml")})
public class MySettingsState implements PersistentStateComponent<MySettingsState> {
    public String myValue = "DEBUG";
    public String EXCLUDE_VAR_FILTER_PATTERN = ".*Role.*";
    public String INCLUDE_VAR_FILTER_PATTERN = "(.*RoleId.*)|(.*RId.*)";
    public String PROJECT_ERL_SRC_ABS_PATH = "";
    public String PROJECT_ERL_TOOLS_ABS_PATH = "";
    public String GEN_TEMPLATE_ABS_ROOT_PATH = "";

    // 项目本地data配置路径
    public String LOCAL_ERL_DATA_CONFIG_ABS_PATH = "";
    // 项目开发data配置路径
    public String DEV_ERL_DATA_CONFIG_ABS_PATH = "";
    public String WPS_ET_EXE_ABS_PATH = "";

    public boolean Is_DEBUG = false;

    public String ERL_NODE_NAME;
    public String ERL_NODE_COOKIE;

    private final List<String> storeStrings = new ArrayList<>();

    // public static final MySettingsState INSTANCE = new MySettingsState();

    public static MySettingsState getInstance() {
        return ApplicationManager.getApplication().getComponent(MySettingsState.class);
    }

    public static List<String> getStoreStrings() {
        return getInstance().storeStrings;
    }

    @Override
    public @Nullable MySettingsState getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull MySettingsState state) {
        XmlSerializerUtil.copyBean(state, this);
    }
}